#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
LL arr[N];
int n, m;
int main()
{
	cin >> n >> m;
	LL l = 0, r = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		l = max(l, arr[i]);
		r += arr[i];
	}
	while (l <= r) {
		LL mid = l + r >> 1;
		int cnt = 1;
		LL temp = 0;
		for (int i = 0; i < n; i++) {
			if (temp + arr[i] <= mid) {
				temp += arr[i];
			}
			else {
				temp = arr[i];
				cnt++;
			}
		}
		if (cnt <= m) {
			r = mid - 1;
		}
		else {
			l = mid + 1;
		}
	}
	cout << l << endl;
	return 0;
}